﻿using M_Ingredient.API.Application.Command.IngredientCommand;
using M_Ingredient.Domain;
using M_Ingredient.Repository.Interface;
using MediatR;
using System.Net.WebSockets;

namespace M_Ingredient.API.Application.CommandHandler.IngredientCommandHandler
{
    public class IngredientBackDanCommandHandler : IRequestHandler<IngredientBackDanCommand, int>
    {
        protected readonly IIngredientRepository ingredientRepository;

        public IngredientBackDanCommandHandler(IIngredientRepository ingredientRepository)
        {
            this.ingredientRepository = ingredientRepository;
        }

        public async Task<int> Handle(IngredientBackDanCommand request, CancellationToken cancellationToken)
        {

            // 使用 LINQ 的 Contains 方法来筛选
           var res =await ingredientRepository.GetAllAsync();

            var ids = request.IngredientId;
             var matchedInspections = res.Where(inspection => ids.Any(idItem => idItem == inspection.IngredientId)).ToList();
           // return matchedInspections;
            return 1;
        }
    }
}
